package vistop.datatypes;

import java.util.Arrays;

public class Vertex extends GeometricalObject implements Comparable<Vertex>{
	public static final int COORD_LEN = 6;
	private double[] coord;
	
	private int id;
	private double x;
	private double y;
	private double z;
	private double[] color;
	
	private boolean incomplete;
	
	
	public Vertex (int id) {
		super(id);
		this.incomplete = true;
	}
	
	public Vertex(int id, double x, double y, double z) {
		super(id);
		this.x = x;
		this.y = y;
		this.z = z;
		this.coord = new double[] { x, y, z , 1, 1, 1 };
		this.color = new double[] { 1, 1, 1 };
		this.incomplete = false;
	}
	
	public Vertex(int id, double x, double y, double z, double[] color) {
		super(id);
		this.x = x;
		this.y = y;
		this.z = z;
		this.coord = new double[] { x, y, z, color[0], color[1], color[2] };
		this.color = color;
		this.incomplete = false;
	}

	public double getX() {
		return x;
	}
	
	public void setX(double x) {
		this.x = x;
		this.incomplete = false;
	}
	
	public double getY() {
		return y;
	}
	
	public void setY(double y) {
		this.y = y;
	}

	public double getZ() {
		return z;
	}
	
	public void setZ(double z) {
		this.z = z;
	}
	
	public void setXYZ(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
		this.incomplete = false;
		//System.out.println("Setting vertex " + this.toString());
	}
	
	public double[] getCoord() {
		return coord;
	}
	
	/**
	 * @return the color
	 */
	public double[] getColor() {
		return color;
	}

	/**
	 * @param color the color to set
	 */
	public void setColor(double[] color) {
		this.color = color;
	}
	
	public boolean isIncomplete() {
		return this.incomplete;
	}

	@Override
	public int compareTo(Vertex arg0) {
		return Double.compare(this.x, arg0.x);
	}
		
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(color);
		long temp;
		temp = Double.doubleToLongBits(x);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(y);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(z);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Vertex other = (Vertex) obj;
		if (!Arrays.equals(color, other.color))
			return false;
		if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
			return false;
		if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
			return false;
		if (Double.doubleToLongBits(z) != Double.doubleToLongBits(other.z))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		String result;
		result = "(" + this.x + ", " + this.y + ", " + this.z + ") ";
		return result;
	}
	
	public String toStringColor() {
		String result = "[  ";
		for (double d : coord) {
			result += d + "  ";
		}
		result += "]";
		return result;
	}
}
